package com.sgb.kjwl.viewmodel.self;


import androidx.databinding.ObservableField;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.UserMsgEntity;
import com.sgb.kjwl.model.entity.businessmanagement.CompanyEntity;
import com.sgb.kjwl.repository.SelfRepertory;
import com.sgb.kjwl.view.ui.activity.self.EnterpriseInformationActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class EnterpriseInfoModel extends BaseViewModel {
    private EnterpriseInformationActivity activity;
    private SelfRepertory repertory;

    public ObservableField<UserMsgEntity> userInfo = new ObservableField<>();
     //创建有参方法赋值
    public EnterpriseInfoModel(EnterpriseInformationActivity activity, SelfRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }
    //通过公司获取我的信息
    public void getMyInfoByCompanyNo(String companyNo) {
        APIManager.getInstance().getMailListAPI().getMyInfoByCompanyNo(companyNo).enqueue(new Callback<BaseEntity<CompanyEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<CompanyEntity>> call, Response<BaseEntity<CompanyEntity>> response) {
                //为空时跳出
                if (response.body() == null) return;
                //数据请求正常时
                if (response.body().getState().equals("ok")) {
                    //返回到activity.showMyInfoByCompanyNo方法进行处理
                    activity.showMyInfoByCompanyNo(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<CompanyEntity>> call, Throwable t) {

            }
        });
    }
}
